<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link type="text/css" rel="stylesheet" href="css/style.css" />
	<script src="js/axios.min.js"></script>
	<script src="js/vue.min.js"></script>
	<script src="js/vote.js"></script>
</head>
<body>
<div id="app">
	<myheader></myheader>
	<div id="vote" class="wrap">
		<h2>查看投票</h2>
		<ul class="list">
			<li>
				<h4>{{vote.vname}}</h4>
				<p class="info">共有{{vote.items.length}}个选项，已有{{vote.userNums}}个网友参与了投票</p>
				<ol>
					<li v-for="i in vote.items">{{i.iname}}
						<div class="rate">
							<div class="ratebg"><div class="percent" :style="{width:getRate(i.records) + '%'}"></div></div>
							<p>{{i.records}}票<span>({{getRate(i.records)}}%)</span></p>
						</div>
					</li>
				</ol>
				<div class="goback"><a href="index.html">返回投票列表</a></div>
			</li>
		</ul>
	</div>
	<div id="footer" class="wrap">
		源辰信息 &copy; 版权所有
	</div>
</div>
<script>
	var v = new Vue({
		el: '#app',
		data:{
			vote:{items:[]}
		},
		created(){
			axios.get("GetVoteServlet"+location.search).then(res=>{
				this.vote = res.data;
				let sum =0;
				this.vote.items.forEach(i=>sum+=i.records);
				this.vote.sum = sum;
			})
		},
		methods:{
			getRate(records){
				return this.vote.sum==0?0:records/this.vote.sum*100;
			}
		}
	})
</script>
</body>
</html>
